package com.gss.autotools;

import com.gss.autotools.mouse.MouseClickEvent;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainFrame extends JFrame {
    private JLabel label;

    public MainFrame() {
        setTitle("显示数据示例");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 300);

        // 创建面板
        JPanel panel = new JPanel();
        getContentPane().add(panel, BorderLayout.CENTER);

        // 创建按钮
        JButton button = new JButton("确定");
        panel.add(button);

        // 创建文本框
        JTextField textField = new JTextField(20);
        panel.add(textField);

        // 创建标签
        label = new JLabel("等待显示数据");
        panel.add(label);

        // 添加按钮点击事件监听器
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取文本框中的数据
                String inputText = textField.getText();

                int pointX = MouseClickEvent.getPointX();
                int pointY = MouseClickEvent.getPointY();

                // 在标签中显示数据
                label.setText(pointX + " , " + pointY);

                // 清空文本框
                textField.setText("");
            }
        });
    }

    public static void main(String[] args) {
        MouseClickEvent.registerGlobalMouse();
        // 创建并显示主窗口
        MainFrame frame = new MainFrame();
        frame.setVisible(true);
    }
}